$(() => {
  let $urlText = $("#urlText");
  let $btnOk = $("#btnOk");
  let $btnClear = $("#btnClear");
  let $realUrl = $("#realUrl");

  let isReq = false;

  $btnClear.on("click", () => {
    if (isReq) {
      return;
    }
    $urlText.val("");
    $realUrl.text("");
  });

  $btnOk.on("click", () => {
    if (isReq) {
      return;
    }
    isReq = true;
    let url = $urlText.val();
    $.post("/twUrl", { url }, (res) => {
      let { url: realUrl } = res;
      if (realUrl) {
        $realUrl.text(realUrl);
      } else {
        $realUrl.text("未能找到视频的真实地址");
      }
      isReq = false;
    });
  });
});
